#!/usr/bin/env python
# -*- coding:utf-8 -*-
########主程序########
import redis
redis_server_host='192.168.136.8'

class RedisHelper():
    def __init__(self):
        self.__conn=redis.Redis(host=redis_server_host) #一个redis连接对象
        self.channel_pub='monitor'      #声明通道名称
        self.channel_sub='monitor'

    def pub(self,monitor_data):
        try:
            self.__conn.publish(self.channel_pub,monitor_data)  #推送数据
            return True
        except:return False

    def subscribe(self):
        sub=self.__conn.pubsub()
        sub.subscribe(self.channel_sub)
        sub.parse_response()
        return sub